import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:route_manager/wx_navigator.dart';
import 'package:wallet_home/page/theme/colors.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import 'package:wallet_home/module_config.dart';
import 'package:wallet_home/walletdetail/models/wallet_detail_model.dart';

class WalletDetailPage extends StatefulWidget {
  const WalletDetailPage({Key key}) : super(key: key);

  @override
  _WalletDetailPageState createState() => _WalletDetailPageState();
}

class _WalletDetailPageState extends State<WalletDetailPage> {
  List<WalletDetailModel> itemList = [];

  @override
  void initState() {
    super.initState();
  }

  _getDetailList(){
    itemList.clear();
    itemList.add(WalletDetailModel(
        "${WXLang.$t("home_wallet_name",package: ModuleConfig.moduleName)}", Text("${SpUtil.getString("walletNameKey")}")));
    itemList.add(WalletDetailModel(
      "${WXLang.$t("home_export_mnemonic",package: ModuleConfig.moduleName)}",
        Icon(
          Icons.keyboard_arrow_right,
          color: ThemeUtils.getThemeColor(
              context: context,
              brightnessColor: Colors.grey[600],
              darkColor: Colors.grey[400]),
        )));
    itemList.add(WalletDetailModel(
        "${WXLang.$t("home_export_private_key",package: ModuleConfig.moduleName)}",
        Icon(
          Icons.keyboard_arrow_right,
          color: ThemeUtils.getThemeColor(
              context: context,
              brightnessColor: Colors.grey[600],
              darkColor: Colors.grey[400]),
        )));
  }

  @override
  Widget build(BuildContext context) {
    _getDetailList();
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        brightness: Brightness.dark,
        title: Text(
          "${WXLang.$t("home_wallet_detail",package: ModuleConfig.moduleName)}",
          style: TextStyle(
              fontSize: 16,
              color: ThemeUtils.getThemeColor(
                  context: context,
                  brightnessColor: Colors.grey[200],
                  darkColor: Colors.white)),
        ),
        leading: IconButton(
          color: ThemeUtils.getThemeColor(
              context: context,
              brightnessColor: Colors.grey[200],
              darkColor: Colors.white),
          icon: Icon(Icons.arrow_back),
          onPressed: () {
             WXNavigator.pop(context: context);
          },
        ),
      ),
      body: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: ListView.separated(
                  itemBuilder: (BuildContext context, int index) {
                    return InkWell(
                      onTap: () {
                        switch (index) {
                          case 0:
                            // WXNavigator.pushNamed(
                            //     context: context, routeName: '/walletNamePage');
                            break;
                          case 1:
                            WXNavigator.pushNamed(
                                context: context,
                                routeName: '/checkPINPage',
                                moduleName: "wallet_authentication",
                                arguments: {
                                  'isHiddenBack': false,
                                  'onCallBack': (String value) {
                                    WXNavigator().popAndPushNamed(
                                        "/mnemonicBackup",
                                        context: context,
                                        moduleName: "wallet_authentication",
                                        arguments: 2);
                                  }
                                });
                            break;
                          case 2:
                            WXNavigator.pushNamed(
                              context: context,
                              routeName: '/privateKeyExportListPage',
                            );
                            break;
                          default:
                            break;
                        }
                      },
                      child: Container(
                        height: 50,
                        color: ThemeUtils.getThemeColor(
                            context: context,
                            brightnessColor: Colors.white,
                            darkColor: Colours.dark_bg_color),
                        padding: EdgeInsets.fromLTRB(15, 0, 12, 0),
                        child: Row(
                          children: <Widget>[
                            Text("${itemList[index].title}"),
                            Spacer(),
                            itemList[index].itemTail,
                          ],
                        ),
                      ),
                    );
                  },
                  separatorBuilder: (BuildContext context, int index) {
                    return Container(
                      color: ThemeUtils.getThemeColor(
                        context: context,
                        brightnessColor: Colors.grey[200],
                        darkColor: Colors.grey[400],
                      ),
                      height: 0.5,
                      margin: EdgeInsets.only(left: 15),
                    );
                  },
                  itemCount: itemList.length),
            )
          ],
        ),
      ),
    );
  }
}
